package main

func main() {

}

/**
 * @Description: 数组方式实现，把数组按照要求重新拼装之后，然后再填充数组
 */
func rotateRight(head *ListNode, k int) *ListNode {
	if k == 0 || head == nil || head.Next == nil {
		return head
	}
	result := new(ListNode)
	resultTemp := result
	nums := make([]int, 0)
	temp := head
	for temp != nil {
		nums = append(nums, temp.Val)
		temp = temp.Next
	}
	newNums := make([]int, 0)
	n := len(nums) - k%len(nums)
	newNums = append(newNums, nums[n:]...)
	newNums = append(newNums, nums[:n]...)
	for _, value := range nums {
		resultTemp.Next = &ListNode{Val: value}
		resultTemp = resultTemp.Next
	}
	return result.Next
}

type ListNode struct {
	Val  int
	Next *ListNode
}
